﻿<cfsilent>
	<cfscript>
	
		event.setArg("pageTitle", "教学任务安排 - 计划任务合班");
		
		targetArgs = structNew();
		
		propAdvice = getProperty("serviceFactory").getBean("taskPropertyAdvice");
		
		termId = event.getArg("TermID");
		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");
		
		courseId = event.getArg("CID");
		teacherId = event.getArg("TCHID");
		teacherName = event.getArg('TNAME','未指定');

		sql = "SELECT 
					t_course.institute_id, 
					t_course.cid, 
					t_institute.institute_name, 
					t_course.course_credit, 
					t_course.course_name, 
					t_course.period, 
					t_course.period_theory, 
					t_course.period_week 
				FROM 
					t_course 
					INNER JOIN t_institute ON t_institute.institute_id = t_course.institute_id 
				WHERE 
					t_course.cid = :courseID ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="courseID", value=courseId, cfsqltype="cf_sql_varchar" );
		rs_courseEntity = queryObj.execute( sql=sql ).getResult(); 
		
		sql = "SELECT 
					t_class.cls_id, 
					t_class.cls_name, 
					t_class.grade, 
					t_plan.cidx, 
					t_campus.campus_name, 
					t_class.cls_size, 
					t_class.cls_scale, 
					t_subject.sbj_short, 
					t_course_nature.cna_name, 
					t_course_prop.prop_name, 
					t_campus.campus_id   
				FROM 
					t_plan 
					INNER JOIN t_class ON t_class.cls_id = t_plan.cls_id 
					INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id 
					INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
					INNER JOIN t_course_nature ON t_course_nature.cna_id = t_plan.cna_id 
					INNER JOIN t_course_prop ON t_course_prop.prop_id = t_plan.prop_id 
				WHERE 
					t_plan.term_id = :termId 
					AND 
					t_plan.cid = :courseId 
					AND 
					t_plan.cidx = '000' 
				ORDER BY 
					t_subject.institute_id, 
					t_class.cls_id ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
		rs_class= queryObj.execute( sql=sql ).getResult(); 
			
		sql = "SELECT 
					DISTINCT t_campus.campus_id, 
					t_campus.campus_name 
				FROM 
					t_plan 
					INNER JOIN t_class ON t_class.cls_id = t_plan.cls_id 
					INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id 
				WHERE 
					t_plan.term_id = :termId 
					AND 
					t_plan.cid = :courseId 
					AND 
					t_plan.cidx = '000' 
				ORDER BY 
					t_campus.campus_name ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
		rs_classCampus = queryObj.execute( sql=sql ).getResult(); 

		sql = "SELECT 
					t_task.tsk_id, 
					t_task.cidx, 
					t_teacher.tch_name, 
					t_task.task_week, 
					t_task.task_period, 
					t_task.task_limite, 
					t_task.task_classes, 
					t_campus.campus_name, 
					t_campus.campus_id, 
					t_classroom_type.cr_type_name, 
					t_task.task_prop 
				FROM 
					t_task 
					INNER JOIN t_teacher ON t_teacher.tch_id = t_task.tch_id 
					INNER JOIN t_campus ON t_campus.campus_id = t_task.campus_id 
					INNER JOIN t_classroom_type ON t_classroom_type.cr_type = t_task.cr_type 
				WHERE 
					t_task.term_id = :termId 
					AND 
					t_task.cid = :courseId 
				ORDER BY 
					t_task.cidx DESC ";
		queryObj = new query( datasource=application.dnsSlave );
		queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
		rs_task = queryObj.execute( sql=sql ).getResult(); 

		sql = "SELECT cr_type, cr_type_name 
				FROM t_classroom_type  
				ORDER BY cr_type ";
		queryObj = new query( datasource=application.dnsSlave );
		rs_clsroomType = queryObj.execute( sql=sql ).getResult(); 
		
		sql = "SELECT campus_id, campus_name 
				FROM t_campus   
				ORDER BY campus_id ";
		queryObj = new query( datasource=application.dnsSlave );
		rs_campus = queryObj.execute( sql=sql ).getResult(); 
		
		currentTab = event.getArg("TabID", "labFormClass");
		
		if ( currentTab eq "labFormClass" and rs_class.recordCount eq 0 and rs_task.recordCount gt 0 ) {
			currentTab = "labTaskClass";
		}
		
		rs_classOnTask = queryNew("cls_id");
		rs_taskEntity = queryNew("term_id");
		
		if ( listLen(event.getArg("TaskID"), ",") eq 3 ) {
			
			currentTab = "TaskDetail";
			
			sql = "SELECT 
						term_id, 
						cidx, 
						cid, 
						tsk_id, 
						task_prop, 
						task_limite, 
						task_week, 
						task_period, 
						cr_type, 
						campus_id, 
						task_desc  
					FROM 
						t_task 
					WHERE 
						tsk_id = :taskId ";
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="taskId", value= event.getArg("TaskID"), cfsqltype="cf_sql_varchar" );
			rs_taskEntity = queryObj.execute( sql=sql ).getResult(); 
			
			sql = "SELECT 
						t_class.cls_id, 
						t_class.cls_name, 
						t_class.grade, 
						t_plan.cidx, 
						t_campus.campus_name, 
						t_class.cls_size, 
						t_class.cls_scale, 
						t_subject.sbj_short, 
						t_course_nature.cna_name, 
						t_course_prop.prop_name, 
						t_campus.campus_id   
					FROM 
						t_plan 
						INNER JOIN t_class ON t_class.cls_id = t_plan.cls_id 
						INNER JOIN t_campus ON t_campus.campus_id = t_class.campus_id 
						INNER JOIN t_subject ON t_subject.sbj_id = t_class.sbj_id 
						INNER JOIN t_course_nature ON t_course_nature.cna_id = t_plan.cna_id 
						INNER JOIN t_course_prop ON t_course_prop.prop_id = t_plan.prop_id 
					WHERE 
						t_plan.term_id = :termId 
						AND 
						t_plan.cid = :courseId 
						AND 
						t_plan.cidx = :courseIdx 
					ORDER BY 
						t_class.cls_id ";
			queryObj = new query( datasource=application.dnsSlave );
			queryObj.addParam( name="termId", value=rs_taskEntity.term_id, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="courseId", value=rs_taskEntity.cid, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="courseIdx", value=rs_taskEntity.cidx, cfsqltype="cf_sql_char" );
			rs_classOnTask = queryObj.execute( sql=sql ).getResult();
										
				
		}
		
		structInsert(targetArgs, "DepID", rs_courseEntity.institute_id);
		structInsert(targetArgs, "CID", rs_courseEntity.cid);
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('classMerge', targetArgs)#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">任课单位 <cfoutput>#rs_courseEntity.institute_name#</cfoutput></span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 course"></i>课程合班 《<cfoutput>#rs_courseEntity.course_name#</cfoutput>》
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labFormClass">class="active"</cfif> id="labFormClass" tabTarget="FormClass">未合班</span>
						<cfif rs_task.recordCount>
							<span <cfif currentTab eq "labTaskClass">class="active"</cfif> id="labTaskClass" tabTarget="TaskClass">教学任务列表</span>
						</cfif>
						<cfif event.isArgDefined("TaskID")>
							<span <cfif currentTab eq "TaskDetail">class="active"</cfif> id="TaskDetail" tabTarget="TaskDetail">任务详细信息</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				<cfif rs_courseEntity.recordCount>
					<div class="noticeBlock">
						<h3>《<cfoutput>#rs_courseEntity.course_name#</cfoutput>》 任课单位: <cfoutput>#rs_courseEntity.institute_name#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>总学时 <em><cfoutput>#rs_courseEntity.period#</cfoutput></em>, 其中理论学时 <em><cfoutput>#rs_courseEntity.period_theory#</cfoutput></em>. 课程总学分:<em><cfoutput>#numberFormat(rs_courseEntity.course_credit, '_.00')#</cfoutput></em></p>
						<hr/>
					</div>
				</cfif>
				
				<div id="FormClass" class="tabContent">
					
					<div id="formBox" class="hidden_elem">
						
						<form id="formCreate" onSubmit="javascript:return processCreate();" class="formWrapper" method="post" action="<cfoutput>#buildURL('taskCreateDo')#</cfoutput>">
							
							<input type="hidden" name="CourseID" value="<cfoutput>#rs_courseEntity.cid#</cfoutput>" />
							<input type="hidden" name="TermID" value="<cfoutput>#termId#</cfoutput>" />
							<input type="hidden" id="ClassIDs" name="ClassIDs" value="" />
							<input type="hidden" id="TeacherID" name="TeacherID" value="<cfoutput>#teacherId#</cfoutput>" />
							
							<input type="hidden" id="ClassCampusID" name="ClassCampusID" value="" />
							
							<div class="label">
								<span class="req">*</span><b>已选班级</b>
								<div id="ClassNames" class="secondRow"></div>
							</div>
							
							<div class="label">
								<span class="req">*</span><b>计划人数</b>
								<input name="PlanSize" id="PlanSize" type="text" class="typeSmallInt" verification="integer" maxlength="5" value="" /><span>计划实际执行人数 <strong id="classSizeReal"></strong></span>
								<p class="notice">教学班计划人数默认上浮15%, 用于重修、转专业及双学位等计划往外学生修读名额. </p>
							</div>
							
							<hr/>
							
							<div class="label">
								<b>排课教室类别</b>
								<select name="ClassroomType">
                                    <cfloop query="rs_clsroomType">
										<option value="<cfoutput>#rs_clsroomType.cr_type#</cfoutput>"><cfoutput>#rs_clsroomType.cr_type_name#</cfoutput></option>
									</cfloop>
								</select>
							</div>
							
							<div class="label">
								<b>上课校区</b>
								<select name="CampusID" id="CampusID">
									<cfloop query="rs_campus">
										<option value="<cfoutput>#rs_campus.campus_id#</cfoutput>"><cfoutput>#rs_campus.campus_name#</cfoutput></option>
									</cfloop>
								</select>
							</div>
							
							<div class="label">
								
								<b>排课设置</b>
								
								<!--- 根据课程周学时 设置排课要求 --->
								<cfswitch expression="#rs_courseEntity.period_week#">
								
									<cfcase value="0">
										<p>不排课<input name="TaskPeriod" type="hidden" value="0" /><input name="WeekStart" type="hidden" value="1" /><input name="WeekEnd" type="hidden" value="16" /></p>
									</cfcase>
									
									<cfcase value="2">
										<p>每周一次课, 安排2小节<input name="TaskPeriod" type="hidden" value="2" /></p>
									</cfcase>
									
									<cfcase value="3">
										<p>每周一次课, 安排3小节<input name="TaskPeriod" type="hidden" value="3" /></p>
									</cfcase>
									
									<cfcase value="4">
										<p>
											<input name="TaskPeriod" type="radio" class="typeRadio" checked="checked" value="2+2" />每周两次课, 每次2小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="4" />每周一次课, 连续4小节
										</p>
									</cfcase>
									
									<cfcase value="5">
										<p>
											<input name="TaskPeriod" type="radio" class="typeRadio" checked="checked" value="3+2" />每周两次课, 一次2小节,一次3小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="5" />每周一次课, 连续5小节
										</p>
									</cfcase>
									
									<cfcase value="6">
										<p>
											<input name="TaskPeriod" type="radio" class="typeRadio" checked="checked" value="3+3" />每周两次课, 每次3小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="4+2" />每周两次课, 一次4小节, 一次2小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="2+2+2" />每周三次课, 每次2小节
										</p>
									</cfcase>
									
									<cfcase value="8">
										<p>
											<input name="TaskPeriod" type="radio" class="typeRadio" checked="checked" value="3+3+2" />每周三次课, 两次3小节, 一次2小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="2+2+2+2" />每周四次课, 每次2小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="4+4" />每周两次课, 每次4小节
										</p>
									</cfcase>
									
									<cfcase value="10">
										<p>
											<input name="TaskPeriod" type="radio" class="typeRadio" checked="checked" value="3+3+2+2" />每周四次课, 两次3小节, 两次2小节
											<input name="TaskPeriod" type="radio" class="typeRadio" value="2+2+2+2+2" />每周五次课, 每次2小节
										</p>
									</cfcase>
									
									<cfcase value="16">
										<p>每周四次课, 两次4小节</p>
										<input name="TaskPeriod" type="hidden" value="4+4+4+4" />
									</cfcase>
									
								</cfswitch>
								
								<cfif rs_courseEntity.period_week gt 0>
								
									<cfset howmanyWeeks = round(0.4+rs_courseEntity.period_theory / rs_courseEntity.period_week) />
									
									<cfset weekArray = [] />
									
									<div class="secondRow">
										<div class="UIBottonRow">
											<i>课程周次单元</i>
											<cfswitch expression="#howmanyWeeks#">
												<cfcase value="4">
													<cfloop list="1,5,9,13" index="start">
														<cfset arrayAppend(weekArray, [start, (start+howmanyWeeks-1)]) />
														<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
													</cfloop>
													<!--- 特殊情况 用于春节、国庆时长调整 --->
													<cfif academicTerm eq "1">
														<cfloop list="4,8,12" index="start">
															<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
														</cfloop>
													</cfif>
												</cfcase>
												<cfcase value="8">
													<cfloop list="1,5,9" index="start">
														<cfset arrayAppend(weekArray, [start, (start+howmanyWeeks-1)]) />
														<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
													</cfloop>
													<!--- 特殊情况 用于春节、国庆时长调整 --->
													<cfif academicTerm eq "1">
														<cfloop list="4,8" index="start">
															<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
														</cfloop>
													</cfif>
												</cfcase>
												<cfcase value="10,11,12,14">
													<cfloop list="1,5" index="start">
														<cfset arrayAppend(weekArray, [start, (start+howmanyWeeks-1)]) />
														<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
													</cfloop>
													<!--- 特殊情况 用于春节、国庆时长调整 --->
													<cfif academicTerm eq "1">
														<cfloop list="4" index="start">
															<a href="javascript:changeWeek(<cfoutput>#start#</cfoutput>,<cfoutput>#(start+howmanyWeeks-1)#</cfoutput>);"><cfoutput>#start#</cfoutput>-<cfoutput>#(start+howmanyWeeks-1)#</cfoutput></a>
														</cfloop>
													</cfif>
												</cfcase>
												<cfcase value="16">
													
													<cfset arrayAppend(weekArray, [1, 16]) />
													
													<a href="javascript:changeWeek(1,16);">1-16</a>
													<a href="javascript:changeWeek(5,18);">5-18</a>
													
													<!--- 特殊情况 用于春节、国庆时长调整 --->
													<cfif academicTerm eq "1">
														<a href="javascript:changeWeek(4,18);">4-18</a>
													</cfif>
												
												</cfcase>
												
												<cfdefaultcase>
													<cfset arrayAppend(weekArray, [1, howmanyWeeks]) />
												</cfdefaultcase>
												
											</cfswitch>
											
											<a href="javascript:changeWeekSet(1);">顺延1周</a>
											<a href="javascript:changeWeekSet(-1);">提前1周</a>
											
										</div>
									</div>

									<div class="secondRow">
										
										<cfif arrayLen(weekArray) gt 1>
												<cfset randWeek = weekArray[randRange(1, arrayLen(weekArray))] />
											<cfelse>
												<cfset randWeek = weekArray[1] />
										</cfif>
										
										起始周 <input name="WeekStart" id="WeekStart" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="<cfoutput>#randWeek[1]#</cfoutput>" />
										结束周 <input name="WeekEnd" id="WeekEnd" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="<cfoutput>#randWeek[2]#</cfoutput>" />
									</div>
									
									<script language="javascript" type="text/javascript">
										//<![CDATA[
										<!--
										function changeWeekSet(offset) {
											
											var start = parseInt($("#WeekStart").val()) + offset;
											var end = parseInt($("#WeekEnd").val()) + offset;
											
											if (start > 0 && start < 16) { $("#WeekStart").val(start); }
											if (end < 19 && end > 0) { $("#WeekEnd").val(end); }
											if (end < start) { $("#WeekEnd").val(start); }											
											
											return void(0);
										}
										
										function changeWeek(start, end) {
											
											$("#WeekStart").val(start);
											$("#WeekEnd").val(end);
											
											return void(0);
										}
										// -->
										//]]>
									</script>
									
								</cfif>

							</div>
							
							<div class="label">
								<b>主讲教师</b>
								<input name="TeacherName" id="TeacherName" type="text" disabled="disabled" class="typeTextDynamic " verification="required" value="<cfoutput>#teacherName#</cfoutput>" /><span id="teacherTrigger" class="btnSearch"></span>
							</div>
							
							<div class="label">
								<b>排课要求</b>
								<textarea name="Describe" id="Describe"><cfoutput>#event.getArg('Describe')#</cfoutput></textarea>
							</div>
							
							<hr/>
							
							<div class="lable">
								<input class="button" type="submit" value="建立教学班" />
								<input id="formReset" class="button" type="button" value="返回" />
							</div>
							
						</form>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							
							function processCreate() {
								
								var teacherID = $("#TeacherID").val();
								
								if (teacherID != "") {
									
									return processVerfiyForm('formCreate');
									
								}
								else {
									alert("请先指定任课教师");
									
									$("#formBox").addClass("hidden_elem");
									$("#teacherBox").removeClass("hidden_elem");
									
									return false;
								}
								
							}
							
							$(document).ready(function() {
								
								$("#teacherTrigger").click(function(){

									$("#formBox").addClass("hidden_elem");
									$("#teacherBox").removeClass("hidden_elem");

								});
								
								$("#formReset").click(function(){
									
									$("#classBox").removeClass("hidden_elem");
									$("#formBox").addClass("hidden_elem");
									
								});
									
							});
							// -->
							//]]>

						</script>
						
					</div>
					
					<div id="teacherBox" class="hidden_elem">
						
						<form id="formSearch" class="formWrapper Transparent" method="post">
							<div class="label">
								<b>教师姓名或职工号</b>
								<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
							</div>
							<hr/>
							<div class="lable">
								<input class="button1" type="submit" value="搜索教师" />
								<input id="formSearchReset" class="button" type="button" value="返回" />
							</div>
						</form>
						
						<div id="formSearchResult" class="UICardTable"></div>
						
						<script language="javascript" type="text/javascript">
							//<![CDATA[
							<!--
							$("input#formSearchReset").click(function(){
								
								$("#formBox").removeClass("hidden_elem");
								$("#teacherBox").addClass("hidden_elem");
								
							});
							
							$("#formSearch").submit(function(){
								
								if (processVerfiyForm('formSearch')) {
									
									$.getJSON(
											'<cfoutput>#buildURL("getTeacherByKeywords")#</cfoutput>',
											{
												'Keywords': $("form#formSearch input#Keywords").val(),
												'seed': (new Date()).getTime()
											},
											function(data) {
												
												$div = $("div#formSearchResult").html("").removeClass("hidden_elem");
												$("form#formAuth").addClass("hidden_elem");
												
												for (var i=0; i<data.length; i++) {
											
													var $element = $("<dl><dt><a><i class='sex" + data[i][2] + "'></i><dd><h3>" + data[i][1] + " [" + data[i][3] + "]" + "</h3><p>(" + data[i][0] + ")</p></dd></a></dt></dl>");
													
													$element
														.attr({
															'TeacherID' : data[i][0],
															'TeacherName' : data[i][1]
														})
														.click(function(){
															
															var name = $(this).attr('TeacherName');
															var id = $(this).attr('TeacherID');
															
															$("form#formCreate input#TeacherID").val(id);
															$("form#formCreate input#TeacherName").val(name + "(" + id + ")");
															
															/* backForm */
															$("#formBox").removeClass("hidden_elem");
															$("#teacherBox").addClass("hidden_elem");
																												
														})
														.appendTo($div);
													
												}
												
											});
								
								}
								
								return false;
							});
							
							// -->
							//]]>
						</script>
						
					</div>

					<div id="classBox">
						<cfif rs_class.recordCount>
							<cfset row = 0 />
							
							<div class="uiOperationBox">
                                <cfloop query="rs_classCampus">
									<a href="javascript:selectClass('<cfoutput>#rs_classCampus.campus_id#</cfoutput>');" class="uiOperationButton"><i class="btn check"></i><span class="btnText"><cfoutput>#rs_classCampus.campus_name#</cfoutput></span></a>
								</cfloop>
								
								<a id="opCreate" href="javascript:void(0);" class="uiOperationButton"><i class="btn execute"></i><span class="btnText">创建新教学任务</span></a>
								<cfif rs_task.recordCount>
									<a id="opAppend" href="javascript:void(0);" class="uiOperationButton"><i class="btn append"></i><span class="btnText">添加到现有教学任务中</span></a>
								</cfif>
							</div>
							
							<table id="classList" class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td width="18"></td>
										<td>行政班</td>
										<td width="50">校区</td>
										<td width="30">年级</td>
										<td width="60">专业</td>
										<td width="48">类别</td>
										<td width="48">课程性质</td>
										<td width="48">计划人数</td>
										<td width="48">实际人数</td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_class">
										<cfset row++ />
										<tr class="editRows" rowid="<cfoutput>#rs_class.cls_id#</cfoutput>">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><a rowid="<cfoutput>#rs_class.cls_id#</cfoutput>" usage="ForClass" class="stat no"></a></td>
											<td><span usage="ForClassNames"><cfoutput>#rs_class.cls_name#</cfoutput></span></td>
											<td><span usage="ForClassCampus" class="hidden_elem"><cfoutput>#rs_class.campus_id #</cfoutput></span><cfoutput>#rs_class.campus_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_class.grade#</cfoutput></span></td>
											<td><cfoutput>#rs_class.sbj_short#</cfoutput></td>
											<td><cfoutput>#rs_class.cna_name#</cfoutput></td>
											<td><cfoutput>#rs_class.prop_name#</cfoutput></td>
											<td align="right"><span usage="ForClassSize" class="numeric"><cfoutput>#rs_class.cls_size#</cfoutput></span></td>
											<td align="right"><span class="numeric"><cfoutput>#rs_class.cls_scale#</cfoutput></span></td>
										</tr>
									</cfloop>
								</tbody>
							</table>
                            
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								$(document).ready(function() {
									
									$("#opAppend").click(function(){
									
										var $classSelected = $("a.yes[usage='ForClass']");
										var classIds = [];
										var classNames = [];
										var planSize = 0;
										
										$classSelected.each(function(){
											
											classIds.push( $(this).attr("rowid") );
											
											var $tr = $("tr[rowid='" + $(this).attr("rowid") + "']");
											
											classNames.push( $("span[usage='ForClassNames']", $tr).text() );
											
											planSize = planSize + parseInt($("span[usage='ForClassSize']", $tr).text());
											
										});
										
										if (classIds.length) {

											$("#ClassAppendIDs").val( classIds.join() );
											
											$("#classBox").addClass("hidden_elem");
											$("#taskBox").removeClass("hidden_elem");
											
										}
										else {
											alert("请至少选择一个班级");
										}
										
									});
									
									$("#opCreate").click(function(){
										
										var $classSelected = $("a.yes[usage='ForClass']");
										var classIds = [];
										var classNames = [];
										var planSize = 0;
										
										$classSelected.each(function(){
											
											classIds.push( $(this).attr("rowid") );
											
											var $tr = $("tr[rowid='" + $(this).attr("rowid") + "']");
											
											classNames.push( $("span[usage='ForClassNames']", $tr).text() );
											
											planSize = planSize + parseInt($("span[usage='ForClassSize']", $tr).text());
											
										});
										
										if (classIds.length) {
											
											$("#ClassIDs").val( classIds.join() );
											$("#PlanSize").val( parseInt(planSize*1.15) );
											$("#classSizeReal").text(planSize);
											$("#ClassNames").text( classNames.join() );

											/*
												$("form#formCreate input#TeacherID").val("");
												$("form#formCreate input#TeacherName").val("未指定");
											*/
											
											$("#CampusID").val( $("#ClassCampusID").val() );
											
											$("#classBox").addClass("hidden_elem");
											$("#formBox").removeClass("hidden_elem");
										}
										else {
											alert("请至少选择一个班级");
										}
																				
									});
									
									$("a[usage='ForClass']", $("#classList")).click(function(){
										
										var rowid = $(this).attr("rowid");
										var status = $(this).hasClass("yes");
										
										var $tr = $("tr[rowid='" + $(this).attr("rowid") + "']");
										var campusId = $("span[usage='ForClassCampus']", $tr).text();

										var $classSelected = $("a.yes[usage='ForClass']");
										
										/* 切换状态数据 */
										if (status) {
											
											$(this).removeClass("yes").addClass("no");
											
											if ($classSelected.length == 1) {
												$("#ClassCampusID").val("");
											}
											
										}
										else {
											
											/* 检查校区代码 */
											if ($("#ClassCampusID").val() == "") {
												$("#ClassCampusID").val(campusId);
											}
											
											if ( $("#ClassCampusID").val() == campusId) {
												$(this).removeClass("no").addClass("yes");
											}
											else {
												alert("不允许跨校区合班");
											}
											
										}
										
									});
									
								});
								
								function selectClass( campusId ) {
									
									/* 设置校区 */
									$("#ClassCampusID").val(campusId);
									
									/* 初始化选择 */
									$("a[usage='ForClass']").removeClass("yes").addClass("no");
									
									$("#classList > tbody > tr").each(function(index, element) {
										
										var $tr = $(element);
										var targetCampusId = $("span[usage='ForClassCampus']", $tr).text();
										
										if ( targetCampusId == campusId ) {
											$("a[usage='ForClass']", $tr).removeClass("no").addClass("yes");
										}
										
									});
									
								}
								
								// -->
								//]]>				
							</script>
								
							<cfelse>
							
							<!--- 查找该学院的下一门课程 --->
                            
                            <cfset sql = "SELECT 
												t_course.cid, t_course.course_name, t_course.course_credit 
											FROM 
												t_plan 
												INNER JOIN t_course ON t_course.cid = t_plan.cid 
											WHERE 
												t_plan.term_id = :termId 
												AND 
												(t_plan.cidx = '000') 
												AND 
												t_course.institute_id = :depID 
											GROUP BY 
												t_course.cid, t_course.course_name,t_course.course_credit 
											ORDER BY 
												t_course.course_name " /> 
                            <cfset queryObj = new query( datasource=application.dnsSlave,maxRows=1 ) /> 
                            <cfset queryObj.addParam( name="termId", value=termId, cfsqltype="cf_sql_char" ) />
                            <cfset queryObj.addParam( name="depID", value=rs_courseEntity.institute_id, cfsqltype="cf_sql_varchar" ) />
                            <cfset rs_courseDepLeft = queryObj.execute( sql=sql ).getResult() /> 
                         
							<div class="noticeBlock">
								<h3>课程安排完毕</h3>
								<p><span class="img icon16x16 message"></span>当前学期该门课程的所有教学计划任务已完成合班</p>
								<ol>
									<cfif rs_courseDepLeft.recordCount>
										<li class="friendly"><span class="img icon10x10 browser"></span><a href="<cfoutput>#buildURL('classMergeByCourse', {CID=rs_courseDepLeft.cid})#</cfoutput>">继续处理该部门的下一门课程: 《<cfoutput>#rs_courseDepLeft.course_name#</cfoutput>》 学分: <cfoutput>#numberFormat(rs_courseDepLeft.course_credit, "_.00")#</cfoutput></a></li>
									</cfif>
								</ol>
							</div>
							
							
							
						</cfif>
							
					</div>
						
					<div id="taskBox" class="hidden_elem">

						<cfif rs_task.recordCount>
							<cfset row = 0 />
							<table id="taskList" class="UIEditable">
								<thead>
									<tr>
										<td width="18"></td>
										<td width="18"></td>
										<td width="40">课序号</td>
										<td width="80">教师</td>
										<td width="50">周次</td>
										<td width="40">周学时</td>
										<td width="48">计划人数</td>
										<td>行政班</td>
										<td width="60">教室类别</td>
										<td width="50">校区</td>
									</tr>
								</thead>
								<tbody>
                                    <cfloop query="rs_task">
										<cfset row++ />
										<cfset propAdvice.parseProperty(rs_task.task_prop) />
										<tr class="editRows" rowid="<cfoutput>#rs_task.tsk_id#</cfoutput>">
											<td class="index"><cfoutput>#row#</cfoutput></td>
											<td><cfif propAdvice.getLocked()><span class="stat locked"></span><cfelse><a rowid="<cfoutput>#rs_task.tsk_id#</cfoutput>" usage="ForTask" class="stat off"></a></cfif></td>
											<td><span class="numeric"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
											<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
											<td><span class="numeric"><cfoutput>#rs_task.task_week#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_task.task_period#</cfoutput></span></td>
											<td><span class="numeric"><cfoutput>#rs_task.task_limite#</cfoutput></span></td>
											<td><cfoutput>#rs_task.task_classes#</cfoutput></td>
											<td><cfoutput>#rs_task.cr_type_name#</cfoutput></td>
											<td><span usage="ForTaskCampus" class="hidden_elem"><cfoutput>#rs_task.campus_id#</cfoutput></span><cfoutput>#rs_task.campus_name#</cfoutput></td>
										</tr>
									</cfloop>
								</tbody>
							</table>				
							<form id="formAppend" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('taskAppendClassDo')#</cfoutput>">
								<input name="ClassAppendIDs" id="ClassAppendIDs" type="hidden" value="" />
								<input name="TaskID" id="TaskID" type="hidden" value="" />
								<div class="lable">
									<input id="formAppendReset" class="button" type="button" value="返回" />
								</div>
							</form>
							
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								$(document).ready(function() {
									
									$("#formAppendReset").click(function(){
										
										$("#classBox").removeClass("hidden_elem");
										$("#taskBox").addClass("hidden_elem");
										
									});
									
									$("a[usage='ForTask']", $("#taskList")).click(function(){
										
										$("a[usage='ForTask']", $("#taskList")).removeClass("on").addClass("off");
										
										var rowid = $(this).attr("rowid");
										var status = $(this).hasClass("off");
										
										var $tr = $("tr[rowid='" + $(this).attr("rowid") + "']");
										
										var campusId = $("span[usage='ForTaskCampus']", $tr).text();
										
										if ( $("#ClassCampusID").val() == campusId) {
											
											$("#TaskID").val(rowid);
											
											$(this).removeClass("off").addClass("on");
											
											$("form#formAppend").submit();
											
										}
										else {
											alert("不允许跨校区合班");
										}
										
									
									});
									
								});
								// -->
								//]]>				
							</script>
							
						</cfif>

					</div>
						
				</div>
				
				<div id="TaskClass" class="tabContent">
					
					<cfif rs_task.recordCount>
						<table id="taskClassList" class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td width="40">课序号</td>
									<td width="100">教师</td>
									<td width="50">周次</td>
									<td width="40">周学时</td>
									<td width="48">计划人数</td>
									<td>行政班</td>
									<td width="50">校区</td>
									<td width="60">教室类别</td>
									<td width="18"></td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_task">
									<cfset structInsert(targetArgs, "TaskID", rs_task.tsk_id, true) />
									<cfset propAdvice.parseProperty(rs_task.task_prop) />
									<tr class="editRows">
										<td><cfif not propAdvice.getLocked()><a href="<cfoutput>#buildURL('taskRemoveDo', targetArgs)#</cfoutput>" class="stat delete"></a></cfif></td>
										<td><span class="numeric"><cfoutput>#rs_task.cidx#</cfoutput></span></td>
										<td><cfoutput>#rs_task.tch_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_task.task_week#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_task.task_period#</cfoutput></span></td>
										<td><span class="numeric"><cfoutput>#rs_task.task_limite#</cfoutput></span></td>
										<td><cfoutput>#rs_task.task_classes#</cfoutput></td>
										<td><cfoutput>#rs_task.campus_name#</cfoutput></td>

										<td><cfoutput>#rs_task.cr_type_name#</cfoutput></td>
										
										<cfif propAdvice.getLocked()>
											<td><span class="stat locked"></span></td>
											<cfelse>
												<cfif (rs_taskEntity.recordCount gt 0) and (rs_taskEntity.tsk_id eq rs_task.tsk_id) >
													<td><span class="stat config"></span></td>
													<cfelse>
													<td><a href="<cfoutput>#buildURL('classMergeByCourse', targetArgs)#</cfoutput>" class="stat struct"></a></td>
												</cfif>
										</cfif>
									</tr>
								</cfloop>
							</tbody>
						</table>	
					</cfif>
				</div>

				<div id="TaskDetail" class="tabContent">
					
					<cfif rs_classOnTask.recordCount>						
					
						<div class="noticeBlock">
							<h3>合班情况</h3>
							<hr/>
						</div>

						<cfset structDelete(targetArgs, "CID", false) />
						
						<cfset structInsert(targetArgs, "TaskID", rs_taskEntity.tsk_id, true) />

						<cfset propAdvice.parseProperty(rs_taskEntity.task_prop) />
						
						<table id="classOperationList" class="UIEditable">
							<thead>
								<tr>
									<td width="18"></td>
									<td>行政班</td>
									<td width="50">校区</td>
									<td width="30">年级</td>
									<td width="60">专业</td>
									<td width="48">类别</td>
									<td width="48">课程性质</td>
									<td width="48">计划人数</td>
									<td width="48">实际人数</td>
								</tr>
							</thead>
							<tbody>
                                <cfloop query="rs_classOnTask">
									<cfset structInsert(targetArgs, "ClassID", rs_classOnTask.cls_id, true) />
									<tr class="editRows">
										<td><cfif propAdvice.getLocked()><span class="stat locked"></span><cfelseif rs_classOnTask.recordCount gt 1><a class="stat yes" href="<cfoutput>#buildURL('taskRemoveClassDo', targetArgs)#</cfoutput>"></a></cfif></td>
										<td><cfoutput>#rs_classOnTask.cls_name#</cfoutput></td>
										<td><cfoutput>#rs_classOnTask.campus_name#</cfoutput></td>
										<td><span class="numeric"><cfoutput>#rs_classOnTask.grade#</cfoutput></span></td>
										<td><cfoutput>#rs_classOnTask.sbj_short#</cfoutput></td>
										<td><cfoutput>#rs_classOnTask.cna_name#</cfoutput></td>
										<td><cfoutput>#rs_classOnTask.prop_name#</cfoutput></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_classOnTask.cls_size#</cfoutput></span></td>
										<td align="right"><span class="numeric"><cfoutput>#rs_classOnTask.cls_scale#</cfoutput></span></td>
									</tr>
								</cfloop>
							</tbody>
						</table>
					</cfif>	

					<cfif (rs_taskEntity.recordCount GT 0) and not propAdvice.getLocked()>
						<div class="noticeBlock">
							<h3>修改教学任务</h3>
							<hr/>
						</div>
						
						<form id="formUpdate" onSubmit="javascript:return processVerfiyForm('formUpdate');" class="formWrapper" method="post" action="<cfoutput>#buildURL('taskUpdateDo')#</cfoutput>">
							
							<input name="TaskID" type="hidden" value="<cfoutput>#rs_taskEntity.tsk_id#</cfoutput>" />
							
							<div class="label">
								<span class="req">*</span><b>计划人数</b>
								<input name="PlanSize" type="text" class="typeSmallInt" verification="integer" maxlength="5" value="<cfoutput>#rs_taskEntity.task_limite#</cfoutput>" />
								
								<cfset realSize = 0 />
                                <cfloop query="rs_classOnTask">
									<cfset realSize = realSize + rs_classOnTask.cls_size />
								</cfloop>
								
								<span>计划实际执行人数 <strong><cfoutput>#realSize#</cfoutput></strong> , 计划容量 <strong><cfoutput>#int(100*rs_taskEntity.task_limite/realSize)#</cfoutput>%</strong></span>
							</div>
							
							<div class="label">
								<b>周次安排</b>
								<div class="secondRow">
									
									<cfset weekPlan = listToArray(rs_taskEntity.task_week, "-") />
									
									起始周 <input name="WeekStart" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="<cfoutput>#weekPlan[1]#</cfoutput>" />
									结束周 <input name="WeekEnd" type="text" class="typeTinyInt" verification="integer" maxlength="2" value="<cfoutput>#weekPlan[2]#</cfoutput>" />
									
									周学时 <input name="TaskPeriod" type="text" class="typeSmallInt" verification="required" value="<cfoutput>#rs_taskEntity.task_period#</cfoutput>" />
									
								</div>
							</div>
							
							<hr/>
							
							<div class="label">
								<b>排课教室类别</b>
								<select name="ClassroomType">
                                    <cfloop query="rs_clsroomType">
										<option <cfif rs_taskEntity.cr_type eq rs_clsroomType.cr_type>selected="selected"</cfif> value="<cfoutput>#rs_clsroomType.cr_type#</cfoutput>"><cfoutput>#rs_clsroomType.cr_type_name#</cfoutput></option>
									</cfloop>
								</select>
							</div>
							
							<div class="label">
								<b>上课校区</b>
								<select name="CampusID" >
									<cfloop query="rs_campus">
										<option <cfif rs_taskEntity.campus_id eq rs_campus.campus_id>selected="selected"</cfif> value="<cfoutput>#rs_campus.campus_id#</cfoutput>"><cfoutput>#rs_campus.campus_name#</cfoutput></option>
									</cfloop>
								</select>
							</div>
							
							<div class="label">
								<b>排课要求</b>
								<textarea style="height:60px;" name="Describe"><cfoutput>#rs_taskEntity.task_desc#</cfoutput></textarea>
							</div>
							
							<hr/>
							
							<div class="lable">
								<input class="button" type="submit" value="更新教学任务" />
							</div>
							
						</form>
						
					</cfif>

									
					
				</div>
				
			</div>
		</li>
	</ul>
</div>